package com.example.demo.controller;

import com.example.demo.mapper.ClassMapper;
import com.example.demo.pojo.ClassInfo;
import com.example.demo.util.Result;
import com.example.demo.vo.ClassesVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ClassController 
{
    @Autowired
    private ClassMapper classMapper;
    @RequestMapping("/findAllClass")
    public Result findAll(@RequestParam("keyword") String keyword)
    {
        List<ClassInfo> list = classMapper.findAllClass(keyword);
        PageInfo pageInfo = new PageInfo<>(list);
        Result result = new Result(200,"查询成功",pageInfo);
        return result;
    }
    @PostMapping("/saveClass")
    public int saveClass(@RequestBody ClassInfo clazz)
    {
        return classMapper.saveClass(clazz);
    }
    @PutMapping("/updateClass")
    public int updateClass(@RequestBody ClassInfo clazz)
    {
        return classMapper.updateClass(clazz);
    }
    @DeleteMapping("/deleteClass")
    public int deleteClass( int id)
    {
        return classMapper.deleteClass(id);
    }
    @GetMapping("/getStudentCountByClass")
    public int getStudentCountByClass(int id)
    {
        return classMapper.getStudentCountByClass(id);
    }
    @GetMapping("/findClasses")
    public Result findClasses()
    {
        List<ClassesVo> list = classMapper.findClasses();
        PageInfo pageInfo = new PageInfo<>(list);
        Result result = new Result(200,"查询成功",pageInfo);
        return result;
    }
}
